
Imports cmplib01

Public Class frmResourceListing

    Private Const c_MODULE As String = "frmResourceListing"

    Private HT As New Hashtable() '// holds all of the resources
    Private ptrGame As CampaignerGameData

    Public Shadows Sub showDialog(ByVal game As CampaignerGameData)
        Try
            ptrGame = game
            Populate()
            list()
            MyBase.ShowDialog()
        Catch ex As Exception
            HandleException(c_MODULE & ".showDialog", ex)
        End Try
    End Sub

    Private Sub Populate()
        Try
            HT = New Hashtable

            '// go through each installation and see if it generates any resources (for the selected faction)
            For Each mem As ChitMember In ptrGame.Chits
                If mem.UnitType = GroundChitClass_cgd.Objective Then
                    If mem.OwningFaction.Equals(ptrGame.selectedFaction) Then
                        For Each poo As ResourcePoolItem In mem.Resources
                            '// see if an entry exists in the hashtable
                            Dim resListItem As ResourceListItem
                            If HT.ContainsKey(poo.resourceTypeptr.ResourceName) Then
                                resListItem = HT.Item(poo.resourceTypeptr.ResourceName)
                            Else
                                resListItem = New ResourceListItem
                                resListItem.resourceName = poo.resourceTypeptr.ResourceName
                                HT.Add(resListItem.resourceName, resListItem)
                            End If
                            '// do whatever magic we must to make this magical... like... we must
                            resListItem.generateAmount += poo.accrueAmount
                            resListItem.totalAmount += poo.localAmount
                        Next
                    End If
                End If
            Next

        Catch ex As Exception
            HandleException(c_MODULE & ".Populate", ex)
        End Try
    End Sub

    Private Sub List()
        '// lists the items in the hashtable
        Try
            Dim key As String
            For Each key In HT.Keys
                Dim ritem As ResourceListItem = HT.Item(key)
                lvwResources.Items.Add(ritem.resourceName & "  [" & ritem.totalAmount & "] +" & ritem.generateAmount)
            Next
        Catch ex As Exception
            HandleException(c_MODULE & ".list", ex)
        End Try
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.Hide()
    End Sub
End Class



'// to make this simple, we have a class to hold the "current" amount and generated amounts of ... stuff. Keyed
'// into a hashtable by resource name
Public Class ResourceListItem
    Public resourceName As String
    Public totalAmount As Long
    Public generateAmount As Long
End Class

